package marshals;
import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

import java.io.IOException;
import java.util.ArrayList;

public class MarshalArray implements Marshal {
    
    public Object readInstance(XmlPullParser parser, String namespace, String name, PropertyInfo expected) 
            throws IOException, XmlPullParserException {
        
        return parser.nextText();
    }

    public void register(SoapSerializationEnvelope cm) {
        cm.addMapping(cm.xsd, "ArrayList", ArrayList.class, this);

    }

    public void writeInstance(XmlSerializer writer, Object obj) throws IOException {
        ArrayList<Object> myArray = (ArrayList<Object>) obj;
        for (int i = 0; i < myArray.size(); i++) {
            writer.text(obj.toString());
            
                //writer.endTag("", "ArrayOfString");
            }
            
        }
    }
